<?php
/**
 * Created by PhpStorm.
 * User: edmmss
 * Date: 2018/12/24
 * Time: 10:04
 */

namespace app\modules\memento;


use yii\base\InvalidArgumentException;

class State
{
    const STATE_CREATED = 'created';
    const STATE_OPENED = 'opened';
    const STATE_ASSIGNED = 'assigned';
    const STATE_CLOSED = 'closed';

    private $_state;

    private static $_validStates = [
        self::STATE_CREATED,
        self::STATE_OPENED,
        self::STATE_ASSIGNED,
        self::STATE_CLOSED,
    ];

    public function __construct(string $state)
    {
        self::ensureIsValidState($state);

        $this->_state = $state;
    }

    private static function ensureIsValidState(string $state)
    {
        if (!in_array($state, self::$_validStates)) {
            throw new InvalidArgumentException('Invalid state given');
        }
    }

    public function __toString()
    {
        // TODO: Implement __toString() method.
        return $this->_state;
    }
}